<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>测试JS条用NATIVE方法</title>
</head>
<body>
	<input type="button" id="test" style="height: 200px;width: 300px;" value="测试" />
	<input type="button" id="iostest" style="height: 200px;width: 300px;" value="IOS测试"/>
	<script type="text/javascript">
		window.onload = function(){
			document.getElementById('test').addEventListener('click', onBtnClick, false);
		}
		function onBtnClick (){
			window.mobile.JsData("hello android!");
		}
		
		function connectWebViewJavascriptBridge(callback) {
	        if (window.WebViewJavascriptBridge) {
	            callback(WebViewJavascriptBridge)
	        } else {
	            document.addEventListener('WebViewJavascriptBridgeReady', function () {
	                callback(WebViewJavascriptBridge)
	            }, false)
	        }
	    }

	    connectWebViewJavascriptBridge(function (bridge) {
	        bridge.init(function (message, responseCallback) {
	            log('JS got a message', message)
	            var data = {'Javascript Responds': 'Wee!'}
	            log('JS responding with', data)
	            responseCallback(data)
	        })

	        bridge.registerHandler('testJavascriptHandler', function (data, responseCallback) {
	            log('ObjC called testJavascriptHandler with', data)
	            var responseData = {'Javascript Says': 'Right back atcha!'}
	            log('JS responding with', responseData)
	            responseCallback(responseData)
	        })

	        var button = document.getElementById('iostest')
	        button.onclick = function (e) {
	            e.preventDefault()
	            var data = 'Hello from JS button'
	            alert('JS sending message'+data)
	            bridge.send(data, function (responseData) {
	                alert('JS got response'+ responseData);
	            })
	        }
	    })
	</script>
</body>
</html>